<template>
  <div id="login">
    <div class="ks-row login-input-phone border-bottom"> <span class="icon-phone login-phone-label"></span> 
        <input class="ks-col login-input1" type="number" placeholder="手机号码" v-model="verifyCodeCondition.cellphoneNumber">
    </div>
    <div class="ks-row border-bottom login-yzm">
        <div class="ks-col">
            <div class="ks-row login-input-yzm"> <span class="icon-yanzheng login-phone-label"></span> 
                <div class="ks-col">
                    <input class="login-input1" type="number" placeholder="验证码"
                    v-model="loginCondition.code">
                </div>
            </div>
        </div>
        <div class="getcode"> 
            <span @click='bindGetCode'>发送验证码</span> 
            <span style="display: none;"> <span>
            </span> 秒后重试</span>
        </div>
    </div>
    <div class="login-btn">
        <button class="btn-color btn-common" @click='bindSubmit'>登录</button>
    </div>
  </div>
</template>
<script>
import api from "../../api/index";
export default {
  name: "login",
  data() {
    return {
      verifyCodeCondition: {
        appType: 0,
        appVersion: "",
        cellphoneNumber: "",
        type: 0
      },
      loginCondition:{
        "appType": 0,
        "appVersion": "0",
        "cellphoneNumber": "",
        "code": "",
        "deviceToken": "0"
      }
    };
  },
  methods: {
    bindSubmit() {
        let self = this;
        this.loginCondition.cellphoneNumber = this.verifyCodeCondition.cellphoneNumber;
        this.$http.post(api.login,this.loginCondition)
        .then(function(response){
            console.log(response);
            if(response.status === 200){
                let token = response.data.data.token;
                self.$store.dispatch('setUserToken',token);
                self.$router.push({path:'home'});
            }
        })
        .catch(function(error){
            console.log(error);
        })
    },
    bindGetCode() {
      if (this.verifyCodeCondition.cellphoneNumber) {//已填写手机号码
        this.$http
          .post(api.getVerifyCode, this.verifyCodeCondition)
          .then(function(response) {
            console.log(response);
          })
          .catch(function(error) {
            console.log(error);
          });
      }
    }
  }
};
</script>
<style>
#login {
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}

.border-bottom {
  border-bottom: 1px solid #d5d5d5;
}

.login-logo {
  width: 70px;
  height: 70px;
  line-height: 100px;
  background-color: #ccc;
  border-radius: 50%;
  margin: 0 auto;
}

.login-input-phone {
  padding: 48px 0 7px;
  background: #fff;
}

.login-input-phone .login-phone-label {
  font-size: 24px;
  padding-right: 24px;
}

.login-yzm {
  padding: 38px 0 9px;
  display: flex;
}

.login-yzm .login-input-yzm {
  background: #fff;
}

.login-yzm .login-input-yzm .login-phone-label {
  font-size: 19px;
  padding-right: 21px;
}

.login-input1 {
  width: 100%;
  border: 0;
  outline: 0;
}

.getcode,
.login-input1 {
  font-size: 16px;
  height: 22px;
}

.getcode {
  background: #fff;
  color: #00afff;
  width: 105px;
  display: block;
  text-align: right;
  line-height: 22px;
  height: 100%;
  margin-top: 20px;
}

.login-btn {
  margin: 30px 0;
}

.btn-common {
  width: 100%;
  background: none;
  border: none;
  font-size: 16px;
  height: 44px;
  border-radius: 0;
}

.btn-common:active {
  background-color: #999;
  color: #fff;
}

.btn-color {
  background-image: linear-gradient(45deg, #00c9e9, #00afff);
  box-shadow: 0 3px 6px 0 rgba(0, 175, 255, 0.16);
  color: #fff;
  border-radius: 1px;
}

.btn-null-color {
  border: 1px solid #00afff;
  color: #00afff;
}

.login-error {
  padding: 0 11px;
  color: #ff6262;
}

.login-error .login-error-icon {
  display: inline-block;
  width: 22px;
  color: #ff6262;
}

.login-wapper {
  width: 100%;
}

.login-wapper .contactus {
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
  color: rgba(0, 0, 0, 0.4);
}

.login-wapper .contactus,
.loginorregister {
  text-align: center;
  font-size: 14px;
  height: 20px;
  line-height: 20px;
}

.loginorregister {
  margin: 15px 0;
  box-sizing: border-box;
  color: #00afff;
}

.loginorregister .login-right {
  font-size: 14px;
}
.ks-col {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
}
</style>
